﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using OLMS.DAL;

namespace OLMS.BLL
{
    public class ArtistBLL
    {
        //根据编号获取音乐类型信息
        public static Artists GetArtistsById(int artistId)
        {
            using (OLMSDBEntities db = new OLMSDBEntities())
            {
                return db.Artists.SingleOrDefault(a => a.ArtistId == artistId);
            }
        }
        //根据歌手姓名查找ID
        public static int GetArtistId(string name)
        {
            using (OLMSDBEntities db = new OLMSDBEntities())
            {
                Artists artists= db.Artists.SingleOrDefault(a => a.Name == name);
                if (artists == null)
                {
                    //如果不存在歌手，创建歌手记录
                    artists = new Artists() { ArtistId = 0, Name = name };
                    db.Artists.Add(artists);
                    db.SaveChanges();
                }

                return artists.ArtistId;
            }
        }
    }
}